import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '../components/Home.vue' //首页
import Login from '../components/Login.vue'  //登录
import Welcome from '../components/Welcome.vue' 
import Class from '../components/class/list.vue' //班级管理
// import Course from '../components/course/list.vue'  //课程管理
import Check from '../components/check/list.vue'  //考勤管理
import Hour from '../components/hour/list.vue'  //课时汇总
import Student from '../components/student/list.vue' //学员管理
import School from '../components/school/list.vue' //学校动态
// import Else from '../components/else/list.vue' //其他
import Classroom from '../components/else/classroom.vue' //else下教室管理
import Teacher from '../components/else/teacher.vue'  //else下教师管理
import Account from '../components/else/account.vue' //else下账号管理
import Course from '../components/else/course.vue'  //课程管理




const routes = [
  {
    path: '/',
    redirect: '/login'
  },

  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/Home',
    name: 'Home',
    component: Home,
    redirect:'/Welcome',
    children:[
      {path:'/welcome',component:Welcome},
      {path:'/class',component:Class},
      {path:'/course',component:Course},
      {path:'/check',component:Check},
      {path:'/hour',component:Hour},
      {path:'/student',component:Student},
      {path:'/school',component:School},
      // {path:'/else',component:Else}, //其他
      {path:'/classroom',component:Classroom},
      {path:'/teacher',component:Teacher},
      {path:'/account',component:Account},
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  //判断访问的页面如果是登录页面则直接放行
  if (to.path == '/login') return next();
  //不是登录页面 则取tiken 如果有token 则放行 没有 跳转到登录页面
  const token = window.sessionStorage.getItem('success_token')
  if (!token) {
      // this.$message.error("请登录");
      // alert("请登录")
      return next('/login')
  }
  next()
})

export default router
